<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>
<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<style type="text/css">
    .wgt_ont2many {
    	width:100%;
    	border-collapse:collapse;
    	margin:1em 0;
    }
	.wgt_ont2many td {
		font:100% Arial, Helvetica, sans-serif;
	}
	.wgt_ont2many th, td {
		text-align:left;
		padding:.5em;
		border:1px solid #fff;
	}
	.wgt_ont2many th {
		background:#328aa4 url(${pageContext.request.contextPath}/assets/images/tr_back.gif) repeat-x;
		color:#fff;
	}
	.wgt_ont2many tr.even td {
		background:#e5f1f4;
	}
	.wgt_ont2many tr.odd td {
		background:#f8fbfc; 
	}
	.wgt_ont2many .row1 {
		width:90px;
	}
	.wgt_ont2many .row2 {
		width:100px;
	}
</style>
<script type="text/javascript">
//<![CDATA[
	(function(){
		DataViewNew={
			${validator}
			addNew:function(){
				<c:forEach items="${entity.properties}" var="p">
					<c:if test="${p.validator != ''}">
						dijit.byId("${p.name}${suffix}").validator = DataViewNew.${p.name};
						dijit.byId("${p.name}${suffix}").set("invalidMessage","${p.invalidMessage}");
					</c:if>
				</c:forEach>
				if(dijit.byId('form_dataview_new').validate()){
					dojo.xhrPost({
						form:'form_dataview_new',
						handleAs:'json',
						load:function(response){
							alert("success");
							DataView.refresh();
						},
						error:function(){
							alert("failed");
						}
					});
				}
			},
			refresh:function(){
				$ku.loadDojoExt({url:"../../inspector/${entity.id}/dataviewnew?dataid=${dataId}",target:"tab_dataview",title:KppModule.commonResource.edit,closable:true,
					onShow:function(){
						dijit.byId("sc_inspector_toolbar").selectChild("tb_inspector_edit",true);
					}});
				dijit.byId("tab_dataview").resize();
			},
			callEdit:function(eid,id,label){
				$ku.showDialog({
					id:"dialog_dataview_new",
					url:"../../inspector/"+eid+"/dataviewnew?dataid="+id+"&dialog=1",
					title:$ksub(KppModule.commonResource.operEdit,[label]),
					resource:Inspector._resource,
					style:"width:660px;height:360px;margin:0px;"});
			},
			remove:function(eid,id,button){
				var options={
					domain:Inspector._resource.dataview,
					refresh:DataViewNew.refresh,
					url:"../../inspector/"+eid+"/datadel/"+id,
					button:dijit.byId("btn_dataviewnew_del"),
					dialogId:"dialog_dataviewnew_delete",
					resource:Inspector._resource
				};
				KppModule.restProxy(options).remove();
			},
			callRemove:function(eid,id,label){
				var delDialog = dijit.byId("dialog_dataviewnew_delete");
				if(!delDialog) delDialog = new dijit.Dialog({
					id:'dialog_dataviewnew_delete',
					title:KppModule.commonResource.confirm,
					style: "padding:0px;width:300px;height:200px;background-color:#FFF;"
				});
				delDialog.set("content", "<div style=\"padding:20px;text-align:center\">"+$ksub(KppModule.commonResource.confirmDelete,[label])+"</div>" +
					"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_dataviewnew_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
					"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">DataViewNew.remove('"+eid+"','"+id+"',this)<\/script>"+
					"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
					"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
					"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('dialog_dataviewnew_delete').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
					"</div>"
				);
				delDialog.show();
			}
		};
	})();
//]]>
</script>
<span style="display:none">To solve IE7/8 script event tag problem.</span>
<div data-dojo-type="dijit/form/Form" id="form_dataview_new" data-dojo-props="action:'${pageContext.request.contextPath}/cgi/app/inspector/${entity.id}/datanew'">
	<div id="tab_dataview_${name}" data-dojo-type="dijit/layout/TabContainer" data-dojo-props="tabPosition:'left-h'">
		<input name="dataId" type="hidden" value="${dataId==null?'':dataId}"></input>
		<c:forEach items="${entity.groups}" var="g">
			<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'${g.name}'">
				<table width="100%">
					<tr>
						<c:set var="index" value="0"></c:set>
						<c:set var="cols" value="${entity.colspan*2}"></c:set>
						<c:forEach items="${g.properties}" var="p" varStatus="loopStatus">
							<c:set var="index" value="${index + p.colspan*2}"></c:set>
							<c:if test="${!loopStatus.first && index > cols}">
								</tr>
									<c:set var="index" value="${cols + p.colspan*2}"></c:set>
									<c:set var="cols" value="${cols + entity.colspan*2}"></c:set>
								<tr>
							</c:if>
							<c:if test="${p.type != 'one2many'}">
								<td>${p.label}</td>
								<td colspan="${p.colspan*2-1}">
									<c:choose>
										<c:when test="${!p.optionFlag}">
											<input name="${p.name}" id="${p.name}${suffix}" required="${p.required}" value="${valueMap==null?'':valueMap[p.name]}" data-dojo-type="${p.showType}" style="width:${p.width};"
												data-dojo-props="constraints:${p.constraints},regExp:'${p.regExp}'"/>
										</c:when>
										<c:otherwise>
											<select name="${p.name}" id="${p.name}${suffix}" required="${p.required}" data-dojo-type="dijit.form.Select" style="width:${p.width};"
												data-dojo-props="">
												<c:forEach items="${p.options}" var="o">
													<option value="${o.id}">${o.label}</option>
												</c:forEach>
											</select>
										</c:otherwise>
									</c:choose>
								</td>
							</c:if>
							<c:if test="${p.type == 'one2many'}">
								<table class="wgt_ont2many" cellspacing="0" cellpadding="0">
									<c:forEach items="${p.referenceEntity.properties}" var="property">
										<c:if test="${property.defaultShow}">
											<th>${property.label}</th>
										</c:if>
									</c:forEach>
									<th colspan="2">修改/删除</th>
									<c:if test="${one2many != null}">
										<c:forEach items="${one2many}" var="data" varStatus="loopStatus">
											<tr class="even">
												<c:forEach items="${p.referenceEntity.properties}" var="property">
													<c:if test="${property.defaultShow}">
														<td>${data[property.name]}</td>
													</c:if>
												</c:forEach>
												<td><a href="#" onclick="DataViewNew.callEdit('${p.referenceEntity.id}','${data.id}','${data.prtno}')">编辑</a></td>
												<td><a href="#" onclick="DataViewNew.callRemove('${p.referenceEntity.id}','${data.id}','${data.prtno}')">删除</a></td>
											</tr>
										</c:forEach>
									</c:if>
								</table>
							</c:if>
						</c:forEach>
					</tr>
				</table>
			</div>
		</c:forEach>
	</div>
</div>